﻿namespace dotnet_notes.Tools
{
    /// <summary>
    /// 配置工具类
    /// </summary>
    public static class AppsettingsTool
    {
        public static ConnectionStrings ConnectionStrings { get; set; } = new ConnectionStrings();

        public static Jwt Jwt { get; set; } = new Jwt();

        public static RefreshJwt RefreshJwt { get; set; } = new RefreshJwt();

        public static void Init(ConfigurationManager configuration)
        {
            ConnectionStrings.SqlServer = configuration.GetConnectionString("SqlServer");

            Jwt.SigningKey = configuration["Jwt:SigningKey"];
            Jwt.Issuer = configuration["Jwt:Issuer"];
            Jwt.Audience = configuration["Jwt:Audience"];
            Jwt.ExpiresMinute = configuration["Jwt:ExpiresMinute"].ToInt();

            RefreshJwt.SigningKey = configuration["RefreshJwt:SigningKey"];
            RefreshJwt.Issuer = configuration["RefreshJwt:Issuer"];
            RefreshJwt.Audience = configuration["RefreshJwt:Audience"];
            RefreshJwt.ExpiresDay = configuration["RefreshJwt:ExpiresDay"].ToInt();
            RefreshJwt.ForcedLogin = configuration["RefreshJwt:ForcedLogin"].ToBool();
        }
    }

    #region 相关模型定义

    public class ConnectionStrings
    {
        public string SqlServer { get; set; }
    }

    public class Jwt
    {
        public string SigningKey { get; set; }

        public string Issuer { get; set; }

        public string Audience { get; set; }

        public int ExpiresMinute { get; set; }
    }

    public class RefreshJwt
    {
        public string SigningKey { get; set; }

        public string Issuer { get; set; }

        public string Audience { get; set; }

        public int ExpiresDay { get; set; }

        public bool ForcedLogin { get; set; }
    }
    
    #endregion
}
